/*
 *   Copyright (C) 2008 - 2009  FireBalls
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// includes
#include "Enemy.h"

Enemy::Enemy() {

    active = false;

    coord.x = 6;
    coord.y = 6;

    course = NORTH;

    speed = 5;
    speed_Control = 0;

    Type = 0;
}

void Enemy::setCoord(int x, int y) {
    coord.x += x;
    coord.y += y;
}

void Enemy::setSurface(SDL_Surface *surf) {

    Surf = surf;
}

SDL_Surface* Enemy::getSurface() {
    return Surf;
}

int Enemy::getX() {
    return coord.x * 25 + 10 + GridX;
}

int Enemy::getY() {
    return coord.y * 25 + 10 + GridY;
}

int Enemy::getCoordX() {
    return coord.x;
}

int Enemy::getCoordY() {
    return coord.y;
}

bool Enemy::getActive() {
    return active;
}

void Enemy::setActive(bool b) {
    active = b;
}

void Enemy::setActive(bool b, Course c, int x, int y, int s, int type) {
    active = b;
    course = c;
    coord.x = x;
    coord.y = y;
    speed = s;
    speed_Control = 0;
    Type = type;
}

int Enemy::getType() {
    return Type;
}

int Enemy::Loop() {

    if(active == false) {
        return -1;
    }


    if(speed_Control == speed) {
        switch(course) {
            case NORTH:
                coord.y -= 1;
                if(coord.y < 0) {
                    active = false;
                    return 1;
                }
                break;
            case EAST:
                coord.x += 1;
                if(coord.x > 12) {
                    active = false;
                    return 1;
                }
                break;
            case SOUTH:
                coord.y += 1;
                if(coord.y > 12) {
                    active = false;
                    return 1;
                }
                break;
            case WEST:
                coord.x -= 1;
                if(coord.x < 0) {
                    active = false;
                    return 1;
                }
                break;
        }
        speed_Control = 0;
        return 0;
    }
    speed_Control++;
    return 0;
}
